//index.js
//获取应用实例
var app = getApp()
var fileData = require('../../utils/data.js')
var req = require('../../utils/reqUtils.js')
Page({
  // 页面初始数据
  data: {
      colors:['red','orange','yellow','green','purple'],
      // banner 初始化
      banner_url: {},
      indicatorDots: true,
      vertical: false,
      autoplay: true,
      interval: 3000,
      duration: 1000,
      circular: true,
      // nav 初始化
      navTopItems: {},
      navSectionItems: {},
      curNavId: 1,
		  curIndex: 0
  },
   
  onLoad:function(){
    
    console.log(fileData.getIndexNavSectionData())
    var that = this
    req.get('/GetBannerData', {}, 1)
    .then(res => {
      that.setData({
        banner_url: res.data
      })
    }),
    req.get('/GetNavTopItems', {}, 1)
    .then(res => {
      that.setData({
        navTopItems: res.data
      })
    }),
    req.get('/GetNavSectionData', {
      typeId:1
    }, 1)
    .then(res => {
      that.setData({
        list: res.data
      })
    })
    // that.setData({
    //   list: that.data.navSectionItems
    // })
    // console.log(this.data)
  },
  //标签切换
  switchTab: function(e) {
      let id = e.currentTarget.dataset.id;
      req.get('/GetNavSectionData', {
        typeId:id  
      }, 1)
      .then(res => {
        this.setData({
          list: res.data
        })
      });
      // let id = e.currentTarget.dataset.id,
      // index = parseInt(e.currentTarget.dataset.index)
      // this.curIndex = parseInt(e.currentTarget.dataset.index)
      // console.log(e)
      // var that = this
      // this.setData({
      //   curNavId: id,
      //   curIndex: index,
      // })
      // console.log(this.data)
  },
  // 跳转至详情页
  navigateDetail: function(e){
    let str=JSON.stringify(e.currentTarget.dataset.unit);
    wx.navigateTo({
      url:'../detail/detail?artype=' + str
    })
  },
  // toDetail: function (e) {
  //   var unit = e.currentTarget.dataset.unit;
  //   console.log(unit)
  // },
  // 加载更多
  loadMore: function (e) {
    console.log('加载更多')
    var curid = this.data.curIndex

    if (this.data.navSectionItems[curid].length === 0) return
    
    var that = this
    that.data.navSectionItems[curid] = that.data.navSectionItems[curid].concat(that.data.navSectionItems[curid])
    that.setData({
      list: that.data.navSectionItems,
    }) 
  },
  // book
  bookTap: function(e){
    wx.navigateTo({
      url:'../book/book?aid='+e.currentTarget.dataset.aid
    })
  }
  
})
